package com.aishua.fire.config.init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aishua.fire.jpa.DictionaryDao;
import com.aishua.fire.jpa.OneLevelMenuDao;
import com.aishua.fire.jpa.PermDao;
import com.aishua.fire.jpa.TwoLevelMenuDao;
import com.aishua.fire.mapper.DictMapper;
import com.aishua.fire.mapper.PermpermteamMapper;

@Component
public class ManualUpdatePermTable {

	@Autowired
	private PermDao permDao;
	
	@Autowired
	private OneLevelMenuDao oneLevelMenuDao;
	@Autowired
	private TwoLevelMenuDao twoLevelMenuDao;
	
	@Autowired
	private Init init;
	
	@Autowired
	private PermpermteamMapper permPermteamMapper;
	
	@Autowired
	private DictMapper dictMapper;
	
	@Autowired
	private DictionaryDao dictDao;
	
	/**
	 * 更新数据库数据
	 */
	public void updatePermTable(){
		//初始化表数据
		init.urlPermInit();
		//持久化url+账户组集列表
		init.initUrlMap(true);
		//删除权限组合权限子集中无用的关联数据---即删除perm表中不存在的id相关
		permPermteamMapper.deleteUnUsedPermPermteam();
	}
	
	/**
	 * 数据库权限模块初始化使用
	 * 
	 */
	public void initPermTable() {
		//清空所有表 
		permDao.deleteAll();
		oneLevelMenuDao.deleteAll();
		twoLevelMenuDao.deleteAll();
		permPermteamMapper.deleteUnUsedPermPermteam();
		//初始化表数据
		init.urlPermInit();
		//持久化url+账户组集列表
		init.initUrlMap(true);
		
		dictDao.deleteAll();
		//初始化字典表数据
		dictMapper.initDatabaseDicts();
	}
	
}
